#include <stdint.h>
#include <stdio.h>
// #include <windows.h>
#include "../windows_service/board/port.h"
#include "../windows_service/board/windows2mcu.h"
#include "../windows_service/can_general_protocol/general_protocol.h"
#include "../windows_service/os_ticket/os_ticket.h"
#include "../windows_service/tlog/tlog.h"
#include "discharge_soc_calibration.h"
#include "temp_capacity_curve.h"

#define TAG "MAIN"

#define CurQmax             2000
#define soc_cell_table_size 3

battery_capacity_table_t battery_capacity_table[] = {
    /* 表格数据，温度必须从低到高，不允许出现两个温度相同的情况，否则会出错 */
    {-20, 70},  //
    {-10, 80},  //
    {0, 85},    //
    {25, 100},  //
    {45, 100},  //
    {60, 100},  //
};
uint8 battery_capacity_table_size = sizeof(battery_capacity_table) / sizeof(battery_capacity_table_t);

discharge_soc_calibration_soc_cell_t temp_minus20_soc_cell_table[soc_cell_table_size] = {
    {250, 2.306},  //
    {150, 2.189},  //
    {50, 2.072},   //
};
discharge_soc_calibration_soc_cell_t temp_minus10_soc_cell_table[soc_cell_table_size] = {
    {250, 2.464},  //
    {150, 2.308},  //
    {50, 2.130},   //
};
discharge_soc_calibration_soc_cell_t temp_0_soc_cell_table[soc_cell_table_size] = {
    {250, 2.828},  //
    {150, 2.527},  //
    {50, 2.144},   //
};
discharge_soc_calibration_soc_cell_t temp_10_soc_cell_table[soc_cell_table_size] = {
    {250, 3.067},  //
    {150, 2.917},  //
    {50, 2.605},   //
};
discharge_soc_calibration_soc_cell_t temp_25_soc_cell_table[soc_cell_table_size] = {
    {250, 3.173},  //
    {150, 3.128},  //
    {50, 2.960},   //
};
discharge_soc_calibration_soc_cell_t temp_40_soc_cell_table[soc_cell_table_size] = {
    {250, 3.176},  //
    {150, 3.137},  //
    {50, 3.042},   //
};

discharge_soc_calibration_t discharge_soc_calibration_table[] = {
    {0, temp_10_soc_cell_table, soc_cell_table_size},          //
    {10, temp_10_soc_cell_table, soc_cell_table_size},        //
    {25, temp_25_soc_cell_table, soc_cell_table_size},        //
    {40, temp_40_soc_cell_table, soc_cell_table_size},        //
};
uint8 discharge_soc_calibration_table_size = sizeof(discharge_soc_calibration_table) / sizeof(discharge_soc_calibration_t);

void main() {
  int test_temp = 5;
  temp_capacity_curve_init(battery_capacity_table, battery_capacity_table_size);
  discharge_soc_calibration_init(discharge_soc_calibration_table, discharge_soc_calibration_table_size);

  // for (int temp = -30; temp < 90; temp++) {
  //   // for (int temp = 20; temp < 90; temp++) {
  //   // TLOGI(TAG, "temp:%d,cur_qmax:%d\n", temp, temp_capacity_curve_cur_qmax_percent_cal(temp));
  //   TLOGI(TAG, "temp:%d,real_cur_qmax:%d\n", temp, temp_capacity_curve_real_cur_qmax_cal(temp, CurQmax));
  // }

  // for (int index = -30; index < 60; index++) {
  //   discharge_soc_calibration_calibrate(index, 20, 3200);
  // }

  for (float index = 0; index < 3.3; index = index += 0.01) {
    TLOGI(TAG, "SOC:%d,temp:%d,cell_volt:%f\n", discharge_soc_calibration_calibrate(test_temp, 200, index), test_temp, index);
  }

  // TLOGI(TAG,"SOC:%d\n",discharge_soc_calibration_calibrate(5, 20, 2.800));

  // os_create_thread(battery_capacity_table_schedule, 1000);

  // os_thread_start();
}